import { request } from "@/axios"

// API LIST
const apiMap = {
    getBanner: { method: 'get', url: '/home/banner' },
    login: { method: 'post', url: '/login' },
    getMenuData: { method: 'get', url: '/menus.json' },
}

function injectRequest(apiObj) {
    const requestMap = {}
    Object.keys(apiObj).forEach((alias) => {
        let { method, url, config } = apiObj[alias]
        method = method.toUpperCase()
        requestMap[alias] = (dataOrParams = {}, instanceConf = {}) => {
            const keyName = ['PUT', 'POST', 'PATCH'].includes(method) ? 'data' : 'params'
            return request({
                method,
                url,
                [keyName]: dataOrParams,
                ...Object.assign(config || {}, instanceConf)
            })
        }
    })
    return requestMap
}


export default injectRequest(apiMap)